package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.dto.DictQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.RuleQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.service.DictService;
import com.yxw.yxnet_cd_center.customer_service.vo.ChannelVo;
import com.yxw.yxnet_cd_center.customer_service.vo.DictionaryVo;
import com.yxw.yxnet_cd_center.customer_service.vo.PortVo;
import com.yxw.yxnet_cd_center.customer_service.vo.YxCsPortRuleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 字典表管理
 * @author liuxin
 * @date 2023.09.17
 */
@CrossOrigin
@RestController
@Api(value = "字典表管理", tags = "字典表管理")
@Slf4j
@RequestMapping("/dict")
public class DictController {

    @Autowired
    private DictService  dictService;

    @ApiOperation(value = "根据类型获取字典值列表")
    @PostMapping(value = "/getDictDataByType")
    public BaseResult<List<DictionaryVo>> getDictDataByType(@RequestBody DictQueryDTO dto) {
        List<DictionaryVo> dataList =dictService.getDictDataByType(dto);
        return ResultHelper.fillWithSuccess(dataList);
    }

    @ApiOperation(value = "根据ID查询字典值")
    @GetMapping(value = "/getDictDataById")
    public BaseResult<DictionaryVo> getDictDataById(@RequestParam(value = "id") Long id) {
        DictionaryVo vo =dictService.getDictDataById(id);
        return BaseResult.doSuccess(vo,"查询成功");
    }

    @ApiOperation(value = "查询渠道列表")
    @GetMapping(value = "/getChannelList")
    public BaseResult<List<ChannelVo>> getChannelList() {
        List<ChannelVo> voList=dictService.getChannelList();
        return BaseResult.doSuccess(voList,"查询成功");
    }

    @ApiOperation(value = "根据渠道查询端口列表")
    @GetMapping(value = "/getPortList")
    public BaseResult<PortVo> getPortList(@RequestParam(value = "id") Long channelId) {
        List<PortVo> voList =dictService.getPortList(channelId);
        return BaseResult.doSuccess(voList,"查询成功");
    }

    @ApiOperation(value = "根据查询规则列表明细列表")
    @PostMapping(value = "/getRuleList")
    public BaseResult<YxCsPortRuleVO> getRuleList(@Valid  @RequestBody RuleQueryDTO dto) {
        List<YxCsPortRuleVO> voList =dictService.getRuleList(dto);
        return BaseResult.doSuccess(voList,"查询成功");
    }

    @ApiOperation(value = "字段表状态修改")
    @PostMapping(value = "/updateDictStatus")
    public BaseResult<PortVo> updateDictStatus(Long id) {
        dictService.updateDictStatus(id);
        return BaseResult.doSuccess(null,"设置成功");
    }
}
